
local chezheng = fk.CreateSkill{
  name = "wk_heg__chezheng",
}

Fk:loadTranslationTable{
  ["wk_heg__chezheng"] = "掣政",
  [":wk_heg__chezheng"] = "你攻击范围外的其他角色：1.成为你使用牌的目标时，取消之；2.成为【杀】的目标结算后，你可以对其造成1点伤害，然后若其未死亡，你失去1点体力或移除此武将牌。",

  ["wk_heg__chezheng_damage"] = "对 %dest 造成伤害",
  ["wk_heg__chezheng_remove"] = "移除武将",
  ["wk_heg__chezheng_loseHp"] = "失去体力",

  ["$wk_heg__chezheng1"] = "风驰电掣，政权不怠！",
  ["$wk_heg__chezheng2"] = "连屏掣政，实为艰事。",
}

local H = require "packages.ol_hegemony.util"

chezheng:addEffect(fk.TargetConfirming, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(chezheng.name) and player ~= target and not player:inMyAttackRange(target) and data.from == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data:cancelTarget(target)
  end,
})

chezheng:addEffect(fk.CardUseFinished, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(chezheng.name) and data.tos and data.card.trueName == "slash" and 
      table.find(data.tos, function(p)
      return p ~= player and not p.dead and not player:inMyAttackRange(p) end)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = data.tos
    for _, p in ipairs(targets) do
      if not p.dead and not player.dead and not player:inMyAttackRange(p) then
        local choices = {"wk_heg__chezheng_damage::"..p.id, "Cancel"}
        local choice = room:askToChoice(player, {choices = choices, skill_name = chezheng.name})
        if choice ~= "Cancel" then
          room:damage{
            from = player,
            to = p,
            damage = 1,
            skillName = chezheng.name
          }
          if not p.dead then
            local choices2 = {"wk_heg__chezheng_remove", "wk_heg__chezheng_loseHp"}
            local choice2 = room:askToChoice(player, {choices = choices2, skill_name = chezheng.name})
            if choice2 == "wk_heg__chezheng_remove" then
            local isDeputy = H.inGeneralSkills(player, chezheng.name)
              if isDeputy then
                H.removeGeneral(player, isDeputy == "d")
              end
            else
              room:loseHp(player, 1, chezheng.name)
            end
          end
        end
      end
    end
  end,
})

return chezheng